using System;
using UnityEngine;
using UnityEngine.Experimental.PlayerLoop;

namespace Prototype.JumpOverTheWorld
{
    public class PlayerController : UnityEngine.MonoBehaviour
    {
        private Rigidbody playerRb;
        private bool isOnGround = true;
        public float jumpForce = 100;
        public float gravityModifier = 1;
        public bool gameOver = false;
        private void Start()
        {
            playerRb = GetComponent<Rigidbody>();
            Physics.gravity *= gravityModifier;
        }

        private void Update()
        {
            if(Input.GetKeyDown(KeyCode.Space) && isOnGround)
            {
                playerRb.AddForce(jumpForce * Vector3.up,ForceMode.Impulse);
                isOnGround = false;
            }
        }

        private void OnCollisionEnter(Collision other)
        {
            if(other.gameObject.CompareTag("Ground"))
            {
                isOnGround = true;
            }
            else if(other.gameObject.CompareTag("Obstacle"))
            {
                gameOver = true;
                Debug.Log("game over;");
            }
        }
    }
}